package ntd.util.modular.msg.controller;

import cn.hutool.core.util.ObjectUtil;
import com.ToolOpt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import ntd.util.config.common.bo.ResponseBO;
import ntd.util.config.common.controller.BaseMybatisController;
import ntd.util.frame.msg.bo.MsgInBO;
import ntd.util.modular.msg.entity.Msg;
import ntd.util.modular.msg.service.MsgService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"公共能力-消息中心"})
@RestController
@RequestMapping("/msg/manager")
public class MsgController extends BaseMybatisController<Msg, MsgService> {

    /**
     * {
        "channelBusinessId": "2c906edb7fd39df1017fd3cc9a54000b",
        "dataJson": "",
        "enumMsgHandle": "JPUSH_PUSH",
        "msgInfo": {
          "content": "测试内容",
          "title": "测试标题"
        },
        "msgSenderUserId": "-1",
        "receiverIds": "16616661666"
      }
     */

    /**
         {
         "channelBusinessId": "40289f5a7e42bd84017e42be9d480000",
         "receiverPhones": "18837132130",
         "dataJson": "{\"templateCode\":\"1\",\"templateParams\":{\"code\":\"123456\"}, \"signId\": \"20941\"}",
         "enumMsgHandle": "JPUSH_SMS",
         "msgSenderUserId": "-20"
         }

        金山云短信发送模板
     {
     "channelBusinessId": "2c906edb7fd39df1017fd3cc9a54000b",
     "receiverPhones": "18837132130",
     "dataJson": "{\"templateCode\":\"207149\",\"templateParams\":{\"site_name\":\"测试站点\", \"warning_type\":\"告警类型\", \"cause\":\"内容信息\"}, \"signId\": \"21295\"}",
     "enumMsgHandle": "JPUSH_SMS",
     "msgSenderUserId": "-20"
     }
     * @param message
     */
    @PostMapping("send")
    @ApiOperation("发送消息")
    public ResponseBO<String> sendMsg(@Validated @RequestBody MsgInBO message) {
        if (ObjectUtil.isNotNull(message.getDataJsonObj())) {
            message.setDataJson(message.getDataJsonObj().toString());
        }
        return new ResponseBO<>(ToolOpt.OPT_MSG.putMsg(message));
    }

}
